<!-- 医院端  新建手术跟台订单-->
<template>
  <div class="newPurchaseList-box">
    <el-container
      class="newPurchase-box"
      :class="{'add-list-newPurchase-box':curPageList.length}">
      <!-- 头部 -->
      <h3 class="title">病人信息</h3>
      <el-form
        :inline="true"
        :model="formInline"
        :rules="rulesdata"
        ref="ruleForm"
        class="demo-ruleForm-top"
        label-width="100px"
      >
        <el-form-item
          label="住院号"
          prop="admissionNumber"
        >
          <el-input
            placeholder="请输入"
            v-model="formInline.admissionNumber"/>
        </el-form-item>
        <el-form-item
          label="姓名"
          prop="sickName">
          <el-input
            placeholder="请输入"
            v-model="formInline.sickName"
            maxlength="11"
          />
        </el-form-item>
        <el-form-item
          label="性别"
          prop="sickSex">
          <!-- <el-input placeholder="请输入" v-model="formInline.sickSex"/> -->
          <el-select
            v-model="formInline.sickSex"
            placeholder="请选择">
            <el-option
              v-for="item in sickSexOptions"
              :key="item.value"
              :label="item.label"
              :value="item.value"/>
          </el-select>
        </el-form-item>
        <el-form-item
          label="年龄"
          prop="sickAge">
          <el-input
            placeholder="请输入"
            maxlength="11"
            @input="changeSickAge(formInline.sickAge,2)"
            v-model="formInline.sickAge"/>
        </el-form-item>
        <el-form-item
          label="科室"
          prop="hspDept">
          <el-input
            placeholder="请输入"
            v-model="formInline.hspDept"/>
        </el-form-item>
        <el-form-item
          label="手术医生"
          prop="operationDoctor">
          <el-input
            placeholder="请输入"
            v-model="formInline.operationDoctor"/>
        </el-form-item>
        <el-form-item
          label="手术时间"
          prop="operationDate">
          <el-date-picker
            v-model="formInline.operationDate"
            type="datetime"
            placeholder="选择日期"/>
        </el-form-item>
        <el-form-item
          label="拟手术名称"
          prop="operationName">
          <el-input
            placeholder="请输入"
            v-model="formInline.operationName"/>
        </el-form-item>
        <el-form-item
          label="备注"
          prop="remark">
          <el-input
            placeholder="请输入"
            v-model="formInline.remark"
            type="textarea"/>
        </el-form-item>
        <!-- <el-form-item
          label="附件"
          prop="url"
          required>

          <m-upload
            class="upload-box"
            :action="uploadUrl"
            :on-success="handleAvatarSuccess"
            :show-file-list="formInline.fileUrl && formInline.fileUrl.includes('pdf')?true:false"
            :file-list="formInline.fileUrl && formInline.fileUrl.includes('pdf')?fileList:[]"
            :on-change="handleFileChange"
            :m-props="{urlObj:formInline,urlStr:'fileUrl'}"
            :on-remove="handleRemove"
            :before-upload="startAvatarUpload"
            :http-request="httpUpload"> -->
        <!-- <el-button size="small" type="primary">点击上传</el-button> -->
        <!-- <el-image
              v-if="(formInline.fileUrl && formInline.fileUrl.includes('png'))||(formInline.fileUrl && formInline.fileUrl.toLowerCase().includes('jpg'))"
              :src="formInline.fileUrl"
              class="avatar"/>
            <i
              v-else-if="(formInline.fileUrl && formInline.fileUrl.includes('pdf'))||!formInline.fileUrl"
              class="el-icon-plus avatar-uploader-icon"/>
          </m-upload>
          <el-button
            v-show="formInline.fileUrl && formInline.fileUrl.includes('pdf')"
            type="text"
            class="preview-pdf"
            @click="previewPdf">预览</el-button>
          <p class="upload-text">（支持jpg/png/pdf/word/excel格式，10M以内）</p>
        </el-form-item> -->
        <el-form-item
          label="附件"
          prop="fileUrl"
          style="display:flex;"
        >
          <!-- <uploadFileMulti
          :max='10'
          :imgsrcarr='formInline.fileUrl'
          /> -->
          <uploadFileMultis
            :imgsrcarr="formInline.fileUrl"
            :attr="imgBindAttr"
            @returnImgUrl="returnImgUrl"
          />
        </el-form-item>
      </el-form>
      <h3 class="title">配送信息</h3>
      <el-header
        height="auto"
        class="form-wrapper">
        <el-form
          :model="purchaseOrderInfo"
          :rules="rules"
          ref="purchaseOrderForm"
          label-width="130px"
          class="demo-ruleForm"
          :inline="true"
        >
          <el-form-item
            label="申请科室"
            prop="applyDeptId">
            <el-select
              v-model="purchaseOrderInfo.applyDeptId"
              filterable
              placeholder="请输入关键词"
              remote
              clearable
              :remote-method="remoteMethod"
              @focus="getDeptList"
            >
              <el-option
                v-for="item in applyDeptList"
                :key="item.id"
                :label="item.departName"
                :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item
            label="收货地址"
            prop="receiveAddressId">
            <el-select
              v-model="purchaseOrderInfo.receiveAddressId"
              :loading="addressLoading"
              placeholder="请选择"
              @change="changeAddress(purchaseOrderInfo.receiveAddressId)"
            >
              <el-option
                v-for="(item, index) in addressList"
                :key="index"
                :label="item.label"
                :value="item.value"
              />
            </el-select>
          </el-form-item>
          <el-form-item
            label="联系人"
            prop="concatMan">
            <el-input
              v-model="purchaseOrderInfo.concatMan"
              disabled/>
          </el-form-item>
          <el-form-item
            label="联系电话"
            prop="concatPhone">
            <el-input
              v-model="purchaseOrderInfo.concatPhone"
              disabled/>
          </el-form-item>
          <el-form-item
            label="配送商"
            prop="deliveryId">
            <el-select
              v-model="purchaseOrderInfo.deliveryId"
              placeholder="请选择"
              @change="changeupCompany(purchaseOrderInfo.deliveryId)"
            >
              <el-option
                v-for="item in deveryList"
                :key="item.id"
                :label="item.value"
                :value="item.id"/>
            </el-select>
          </el-form-item>
          <el-form-item
            label="供应商"
            prop="userPhone">
            <el-select
              clearable
              v-model="purchaseOrderInfo.upCompanyId"
              :disabled='!purchaseOrderInfo.deliveryId'
              placeholder="请选择">
              <el-option
                v-for="item in changeCompanyList"
                :key="item.id"
                :label="item.value"
                :value="item.id"/>
            </el-select>

          </el-form-item>
        </el-form>
      </el-header>
      <!-- 列表模块 添加产品-->
      <h3 class="title">添加产品</h3>
      <div
        class="top-add-button-wrapper"
        v-if="!isEmptyList">
        <div class="title-info">
          <span>已选择产品数量 : {{ computedCount }}</span>
          <span>品种数 :{{ companyOrderTypeCount }}</span>
          <span class="order-total-amount">金额合计(元) :<span style="color: red;">
            {{ formatPrice(orderTotalAmount()) }}
          </span></span>
        </div>
        <span class="add-button">
          <el-button
            type="primary"
            @click="openAddProductDialog"
            size="small">添加产品</el-button>
          <el-button
            type="button"
            @click="batchDelete"
            size="small">批量删除</el-button>
        </span>
      </div>
      <div>
        <el-editable
          v-if="!isEmptyList"
          v-loading="tableLoading"
          :data="curPageList"
          height="500"
          :columns="purchaseOrderProductListColumns"
          @selection-change="handleSelectionChange"
        >
          <template
            slot="default-registNo"
            slot-scope="scope">
            <div>
              <cell-registration
                :key="scope.row.registNo"
                :regis-no="scope.row.registNo"
                :content="'注册证已过期，点击查看详细信息'"
                :status="scope.row.expireStatus"
                :regis-data="scope.row.registInfo"
              />
            </div>
          </template>
          <!-- 规格型号 -->
          <template
            slot="default-specification"
            slot-scope="scope">
            <div>{{ scope.row.spec }} {{ scope.row.model }}</div>
          </template>
          <template
            slot="default-purchaseNum"
            slot-scope="scope">
            <el-input-number
              v-model="scope.row.count"
              @change="resetIllegalInput(scope,$event)"
              size="mini"
              :step="1"
              :min="1"
              :max="9999999"
              label="描述文字"
              step-strictly
            />
          </template>
          <template
            slot="default-action"
            slot-scope="scope">
            <el-button
              size="small"
              @click.stop="deleteOrderProductItem(scope)"
              type="text text-danger"
            >删除</el-button>
          </template>
        </el-editable>
      </div>

      <div
        class="center-add-button-wrapper"
        v-if="isEmptyList">
        <el-button
          type="primary"
          @click="openAddProductDialog">+ 添加产品</el-button>
      </div>
      <!-- 选择采购产品 -->
      <add-product-dialog
        :dialog-visible.sync="addProductDialogShow"
        title="选择采购产品"
        :query-url="hospitalHosCooperationProdList"
        query-method="post"
        :extra-query="sCompanyQuery"
        :current-products="purchaseOrderProductList"
        @confirmDialog="addSelectionToProductList"
        @cancelDialog="cancelAddSelection"
        :type='dialogType'
      />
    </el-container>
  </div>
</template>

<script>
import { mapState } from 'vuex'
import { purchaseOrderProductListColumns, sickSexOptions } from './const'
import SearchForm from '@components/businesscomponents/search'
import ElEditable from '@components/el-editable'
import CellRegistration from '@/moduleComponents/common/detail/cell-registration'
import AddProductDialog from '@/moduleComponents/beforeSettle/hospitalSide/addProduct'
import { PAGE_NUMBER, PAGINATION_LAYOUT, PDF_LIMIT_SIZE } from '@const/common'
import { computeRate, computeAdd } from '@const/filter'
import Addheadcontent from '@components/businesscomponents/addheadcontent'
import { createPurchaseOrder, editPurchaseOrder } from '@const/orderCenterApi'
import { partnerList } from '@const/authCenterApi'
import { formatPrice } from '@const/agencySaas'
import { cloneDeep, isObject, uniqBy, hasIn } from 'lodash'
import { hospitalHosCooperationProdList, enumSelectorHosDealerGetDealers, enumSelectorhosDealerSuperDealer } from '@const/productCenterApiV2'
import uploadFileMultis from '@components/businesscomponents/uploadFileMultis'
import {
  getAddressListAll,
  hospitalNeedOrderControllerFollowOrder
} from '@const/beforeSettleApi'
import { organizationUcSearchCurr } from '@const/staffCenterApi'
import { fileUpload } from '@const/api'
import { format } from 'path'
import { formatDate } from '@const/filter.js'
const imageFileLimit = '.png,.jpg,.jpeg,.bpg,.pdf,.xls,.xlsx,.docx,.doc'
export default {
  components: {
    ElEditable,
    SearchForm,
    AddProductDialog,
    Addheadcontent,
    uploadFileMultis,
    CellRegistration
  },
  data () {
    return {
      hospitalHosCooperationProdList,
      purchaseOrderProductListColumns, // 页面产品列表表头
      addProductDialogShow: false,
      addressList: [],
      addressLoading: false,
      purchaseOrderInfo: {
        receiveAddressId: '',
        applyDeptId: '',
        concatMan: '',
        concatPhone: '',
        deliveryId: '',
        upCompanyId: ''
      },
      formInline: {
        admissionNumber: '',
        sickName: '',
        sickAge: null,
        sickSex: 0,
        hspDept: '',
        operationDoctor: '',
        operationDate: '',
        operationName: '',
        remark: '',
        fileUrl: []
      },
      sickSexOptions,
      computedCount: 0,
      purchaseOrderProductList: [],
      purchaseOrderProductTableList: [],
      rules: {
        receiveAddressId: [
          { required: true, message: '请选择收货地址', trigger: 'change' }
        ],
        deliveryId: [
          { required: true, message: '请选择配送商', trigger: 'change' }
        ],
        upCompanyId: [
          { required: true, message: '请选择供应商', trigger: 'change' }
        ],
        applyDeptId: [{ required: true, message: '请输入科室名称', trigger: 'change' }]
      },
      tableLoading: false, // 这里的loading只有在扩展编辑订单功能之后才有用
      selectList: [],
      imgBindAttr: { disabled: false },
      rulesdata: {
        admissionNumber: [{ required: true, message: '请输入住院号', trigger: 'blur' }],
        sickName: [{ required: true, message: '请输入姓名', trigger: 'blur' }],
        sickAge: [{ required: true, message: '请输入年龄(数字)', trigger: 'blur' }],
        sickSex: [{ required: true, message: '请输入性别', trigger: 'blur' }],
        hspDept: [{ required: true, message: '请输入科室名称', trigger: 'blur' }],
        operationDoctor: [{ required: true, message: '请输入手术医生名称', trigger: 'blur' }],
        operationDate: [{ required: true, message: '请选择手术日期', trigger: 'blur' }],
        operationName: [{ required: true, message: '请输入手术名称', trigger: 'blur' }]
      },
      fileList: '',
      uploadUrl: fileUpload,
      dialogType: 'hospital',
      applyDeptList: [],
      enclosureList: [],
      deveryList: [],
      changeCompanyList: []
    }
  },
  watch: {
    curPageList: {
      immediate: true,
      handler (val) {
        let sumCount = 0
        this.curPageList.forEach(item => {
          sumCount += item.count
        })
        this.computedCount = sumCount
      }
    }
    // formInline: {
    //   immediate: true,
    //   deep: true,
    //   handler (val) {
    //     // eslint-disable-next-line no-empty
    //     if (parseFloat(val.sickAge).toString() === 'NaN') {
    //       console.log(val.sickAge)
    //     }
    // let sumCount = 0
    // this.curPageList.forEach(item => {
    //   sumCount += item.count
    // })
    // this.computedCount = sumCount
    //   }
    // }
  },
  computed: {
    ...mapState(['companyId', 'companyType', 'roleType']),

    isEmptyList () {
      return this.purchaseOrderProductList.length === 0
    },

    curPageList () {
      return this.purchaseOrderProductTableList
    },
    companyOrderTypeCount () {
      return this.curPageList.length
    },

    sCompanyQuery () {
      return {
        // downEnterpriseId: this.companyId,
        dealerId: this.purchaseOrderInfo.sCompanyId
      }
    }
  },

  mounted () {
    let obj = {
      type: 'btn',
      arr: [{ type: 'primary', val: '提交', handle: this.handleSubmit }]
    }
    this.$store.commit('changeLayoutHandle', obj)
    // 查询收货地址
    this.getAddressList()
    this.getDeverList()
  },
  methods: {
    formatPrice,
    // 合并行
    batchDelete () {
      if (!this.selectList.length) {
        this.$message.warning('请选择产品')
        return
      }
      this.purchaseOrderProductList.forEach(item => {
        this.selectList.forEach(ite => {
          if (item.dealerAuthItemId === ite.dealerAuthItemId) {
            this.purchaseOrderProductList = this.purchaseOrderProductList.filter(
              it => {
                return it.dealerAuthItemId !== item.dealerAuthItemId
              }
            )
            this.selectList = this.selectList.filter(it => {
              return it.dealerAuthItemId !== item.dealerAuthItemId
            })
            this.ProductList()
          }
        })
      })
    },
    // 校验住院号
    // changeAdmissionNumber (val) {
    //   if (Number(val).toString() === 'NaN') {
    //     this.formInline.admissionNumber = val.slice(0, val.length - 1)
    //     if (Number(this.formInline.admissionNumber).toString() === 'NaN') {
    //       this.changeAdmissionNumber(this.formInline.admissionNumber)
    //     }
    //   }
    // },
    changeSickAge (val) {
      if (Number(val).toString() === 'NaN') {
        this.formInline.sickAge = val.slice(0, val.length - 1)
        if (Number(this.formInline.sickAge).toString() === 'NaN') {
          this.changeSickAge(this.formInline.sickAge)
        }
      }
    },
    // 获取配送商对应的供应商
    changeupCompany (id) {
      this.purchaseOrderInfo.upCompanyId = ``
      this.$axios({
        method: 'post',
        url: enumSelectorhosDealerSuperDealer,
        data: {
          enterpriseId: id
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        let content = obj.content
        this.changeCompanyList = content
      })

      // 2020-2-12 qiyu #4680 院端跟台订单收货时，收货数量展示错误。
      this.$set(this.purchaseOrderInfo, 'sCompanyId', id)
    },
    getDeverList () {
      this.$axios({
        method: 'post',
        url: enumSelectorHosDealerGetDealers,
        data: {
          // dealerName: this.$store.state.companyName
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        let content = obj.content
        this.deveryList = content
      })
    },
    // 远程搜索科室
    remoteMethod (query) {
      this.$axios({
        method: 'post',
        url: organizationUcSearchCurr,
        data: {
          departName: query
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        this.applyDeptList = obj.content
      })
    },
    getDeptList () {
      this.$axios({
        method: 'post',
        url: organizationUcSearchCurr,
        data: {
          departName: ``
        }
      }).then(res => {
        let obj = hasIn(res, 'data.payload') ? res.data.payload : {}
        this.applyDeptList = obj.content
      })
    },
    handleSelectionChange (list) {
      this.selectList = list
    },
    // 照片上传成功的回调
    handleAvatarSuccess (res, file, type) {
      this.formInline.fileUrl = URL.createObjectURL(file.raw)
    },
    // 文件列表移除文件时的钩子
    handleRemove (file, fileList) {
      this.formInline.fileUrl = ''
    },
    returnImgUrl (imgArr) {
      this.enclosureList = []
      this.formInline.fileUrl = imgArr
      let index = 1
      this.formInline.fileUrl.forEach(item => {
        var obj = {}
        obj.fileName = item.name
        obj.filePath = item.url
        this.enclosureList.push(obj)
      })
    },
    httpUpload ({ file }) {
      let fd = new FormData()
      fd.append('file', file)
      this.$axios({
        method: 'post',
        url: fileUpload,
        headers: { 'Content-Type': 'multipart/form-data' },
        data: fd
      }).then(res => {
        const { data } = res
        if (!Number(res.code)) {
          this.$message.success('照片关联上传成功')
          // 赋值上传后的地址给文档
          this.formInline.fileUrl = res.data.payload
          this.$refs['formInline'].clearValidate()
        } else {
          this.$message.error(data.msg)
        }
      })
      return false // 返回false不会自动上传
    },
    // 图片上传前
    startAvatarUpload (file) {
      // 条件拦截
      this.uploadActon(file, 'produce')
    },
    // 证照上传限制
    uploadActon (file) {
      // const isJPG = file.type.includes('image/')
      const isJPG = imageFileLimit.includes(
        file.name.replace(/.+\./, '').toLowerCase()
      )
      if (!isJPG) {
        this.$message.error('上传证照只能是图片,PDF,word,excel格式!')
        return false
      }
      const isLt2M = file.size / 1024 / 1024 < 10
      if (!isLt2M) {
        this.$message.error('上传图片或者附件大小不能超过 10MB!')
        return false
      }
    },
    // 预览
    previewPdf () {
      this.$pdfViewer({ url: this.formInline.fileUrl, title: 'pdf' })
    },
    // 文件状态改变时的钩子，添加文件、上传成功和上传失败时都会被调用
    handleFileChange (file, fileList) {
      this.fileList = fileList.slice(-1)
    },
    // 收货地址切换获取联系人和联系电话
    changeAddress (value) {
      let findItem = this.addressList.find(item => {
        return item.value === value
      })
      this.purchaseOrderInfo.concatPhone = findItem.userPhone
      this.purchaseOrderInfo.concatMan = findItem.userName
    },
    // 获取详情

    orderTotalAmount () {
      let amount = 0
      this.purchaseOrderProductList.forEach(item => {
        if (item.count) {
          amount += item.count * item.buyPrice
        }
      })
      return amount
    },

    getAddressList () {
      this.addressLoading = true
      this.$axios
        .$post(getAddressListAll, {
          // 断数据来源；1，医院端  2，配送商端'
          yp: 1
        })
        .then(res => {
          const list = isObject(res.payload.content) ? res.payload.content : []
          this.addressList = list.map(item => {
            let obj = {}
            obj = {
              value: item.id,
              label:
                item.province + item.city + item.area + item.detailedAddress,
              userName: item.userName,
              userPhone: item.userPhone
            }
            return obj
          })
        })
        .catch(e => {})
        .finally(() => {
          this.addressLoading = false
        })
    },

    resetIllegalInput (scope, value) {
      let id = scope.row.dealerAuthItemId
      this.purchaseOrderProductList.forEach(item => {
        if (item.dealerAuthItemId === id) {
          item.count = Math.round(value)
        }
      })
      this.ProductList()
    },

    openAddProductDialog () {
      this.$refs.purchaseOrderForm.validate(valid => {
        this.$refs.ruleForm.validate(vali => {
          if (valid && vali) {
            this.addProductDialogShow = true
          }
        })
      })
    },

    addSelectionToProductList (selection) {
      // 如果选择项中已经添加过了，就按最新的数量更新, 未添加过就格式化一下字段添加
      // todo 如果页面中已经添加了，但在弹窗中又取消了选中怎么处理？
      selection.forEach(item => {
        const addedItem = this.purchaseOrderProductList.find(
          addedItem => addedItem.dealerAuthItemId === item.dealerAuthItemId
        )
        item.xUpEnterpriseName = item.upEnterpriseName
        if (addedItem) {
          addedItem.purchaseNum = item.purchaseNum
          this.purchaseOrderProductList.forEach((its, index) => {
            if (addedItem.dealerAuthItemId === its.dealerAuthItemId) {
              its.count++
            }
          })
        } else {
          item.count = item.purchaseNum
          this.purchaseOrderProductList.push(item)
        }
      })

      this.ProductList()
      this.addProductDialogShow = false
    },

    // 重组数据 计算金额
    ProductList () {
      // 从新组装数据
      let purchaseOrderProductList = cloneDeep(this.purchaseOrderProductList)
      let newArr = []
      purchaseOrderProductList.forEach(item => {
        let obj = this.purList(item.upEnterpriseId)
        newArr.push(obj)
      })
      // 去重
      let uniqByArr = uniqBy(newArr, 'id')

      // 得到最后的数据格式
      let lastArr = []
      uniqByArr.forEach(item => {
        let itemArr = item.arr
        itemArr.forEach(data => {
          lastArr.push(data)
        })
      })
      this.purchaseOrderProductTableList = lastArr
    },

    // 筛选重组合数据
    purList (id) {
      let data = cloneDeep(this.purchaseOrderProductList)
      let arr = []
      // 计算金额
      let num = 0
      let upEnterpriseName = ''
      let upEnterpriseId = ''
      data.forEach(item => {
        if (id === item.upEnterpriseId) {
          num += Number(item.buyPrice || 0) * Number(item.count || 1)
          upEnterpriseName = item.upEnterpriseName
          upEnterpriseId = item.upEnterpriseId
        }
      })
      let numObj = {
        upEnterpriseName: upEnterpriseName,
        upEnterpriseId: upEnterpriseId,
        num: num
      }
      // arr.push(numObj)

      // 查询相同供应商数据重组
      data.forEach(item => {
        if (id === item.upEnterpriseId) {
          arr.push(item)
        }
      })
      let obj = {
        id: id,
        arr: arr
      }

      return obj
    },

    cancelAddSelection () {
      this.addProductDialogShow = false
    },

    deleteOrderProductItem (scope) {
      this.purchaseOrderProductList.forEach((item, index) => {
        if (item.dealerAuthItemId === scope.row.dealerAuthItemId) {
          this.purchaseOrderProductList.splice(index, 1)
        }
      })
      this.ProductList()
    },
    handleSubmit () {
      this.createPurchaseOrder()
    },

    createPurchaseOrder () {
      this.$refs.purchaseOrderForm.validate(valid => {
        this.$refs.ruleForm.validate(vali => {
          if (valid && vali) {
            this.purchaseOrderProductList.forEach(item => {
              item.purchaseNum = item.count
            })
            // 根据科室id获取科室名称
            const applyDept = this.applyDeptList.filter(item => {
              return item.id === this.purchaseOrderInfo.applyDeptId
            })[0].departName
            // 根据收货地址id 获取收货地址名称
            const receiveAddress = this.addressList.filter(item => {
              return item.value === this.purchaseOrderInfo.receiveAddressId
            })[0].label
            const deliveryName = this.deveryList.filter(item => {
              return item.id === this.purchaseOrderInfo.deliveryId
            })[0].value
            const upCompanyName = this.purchaseOrderInfo.upCompanyId ? this.changeCompanyList.filter(item => {
              return item.id === this.purchaseOrderInfo.upCompanyId
            })[0].value : ''
            let postArr = this.purchaseOrderProductList.map(item => {
              return {
                category: item.bigType,
                dealerAuthItemId: item.dealerAuthItemId,
                hosAuthItemId: item.hosAuthItemId,
                itemCode: item.code,
                manufacturer: item.manufacturer,
                minUnit: item.unit,
                nameCn: item.prodName,
                price: item.buyPrice,
                productType: item.model,
                purchaseNum: item.purchaseNum,
                registrationNumber: item.registNo,
                registrationId: item.registId,
                specification: item.spec,
                unit: item.unit
              }
            })
            this.formInline.operationDate = formatDate(
              this.formInline.operationDate,
              'YYYY-MM-DD HH:mm:ss'
            )
            const postData = {
              ...this.formInline,
              ...this.purchaseOrderInfo,
              productFom: postArr,
              receiveAddress: receiveAddress,
              applyDept: applyDept,
              deliveryName: deliveryName,
              deliveryId: this.purchaseOrderInfo.deliveryId,
              upCompanyId: this.purchaseOrderInfo.upCompanyId,
              upCompanyName: upCompanyName
            }
            let fileList = this.formInline.fileUrl.map(item => {
              return {
                fileUrl: item.url,
                fileName: item.name
              }
            })
            postData.fileUrl = fileList
            // let fileList = this.formInline.fileUrl.map(item => item.url)
            // postData.fileUrl = fileList
            this.$axios
              .$post(hospitalNeedOrderControllerFollowOrder, postData)
              .then(res => {
                if (res.code === '0') {
                  this.$message({ type: 'success', message: '新增成功' })
                  this.$router.push(
                    '/hospitalSide/orderTracking/operationOrderList'
                  )
                }
              })
              .catch(e => {})
          }
        })
      })
    }
  }
}
</script>

<style lang='less'>
.newPurchaseList-box {
  position: absolute;
  overflow: auto;
  .upEnterpriseNameBox {
    font-size: 16px;
    font-weight: 600;
  }
  .add-list-newPurchase-box {
    position: absolute;
    overflow: auto;
  }

  .newPurchase-box {
    overflow: auto;

    .form-wrapper {
      margin-top: 16px;
      margin-left: -56px;
    }

    .title {
      border-bottom: 1px solid #eee;
      padding-bottom: 10px;
    }
    .top-add-button-wrapper {
      display: flex;
      margin: 24px 0;
      justify-content: space-between;
      .title-info {
        span {
          margin-right: 16px;
        }
      }
      .order-total-amount {
        font-size: 16px;
        font-weight: 500;
      }
    }

    .center-add-button-wrapper {
      flex: 1;
      display: flex;
      justify-content: center;
      align-items: center;
      margin: 100px 0;
    }
    .demo-ruleForm {
      // display: flex;
      // width: 500px;
      // margin-top: 16px;
      .el-select {
        width: 100%;
      }
    }
    .demo-ruleForm-top {
      margin-top: 16px;
    }
  }
}

</style>
